/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package data;
import java.sql.Connection;
import java.util.Properties;
import java.sql.SQLException;
//import oracle.jdbc.pool.OracleDataSource;
import oracle.jdbc.OracleConnection;
import oracle.jdbc.pool.OracleDataSource;
/**
 *
 * @author NS
 */
public class Connect {
    private Connection connection;
	//private static String connectionString = "jdbc:oracle:thin:isstest/Oracle123@portal.oracle.vn:1521:orcl";
	
    public Connect(){
		connection = null;
	}
    public String connectData(String usr, String pwd){
            OracleDataSource ds = null;
            try {
                ds = new OracleDataSource();
                ds.setDriverType("thin");
                ds.setServerName(Constant.OracleAddress);
                ds.setPortNumber(1521);
                ds.setDatabaseName("orcl");
                ds.setUser(usr);
                ds.setPassword(pwd);
                Properties p = new Properties();
                p.setProperty("internal_logon","sysdba");
                connection = ds.getConnection();
                
                return "success";
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                //e.printStackTrace();
                System.out.println(e.getMessage());
                return e.getMessage();
            }
	}
    public Connection getConnection(){
        return this.connection;
    }
    public void closeConnection(){
            if(connection != null)
                try {
                    connection.close();
                } catch (SQLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
	}
}
